<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>投票系统 - 联系管理员</title>
    <!-- 引入Layui CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.8.17/css/layui.min.css">
    <script src="<c:url value="/js/jquery-3.7.1.min.js"/>"></script>
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        /* 自定义样式 - 保持与登录页一致 */
        body {
            background-color: #f8f9fa;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            padding: 20px;
            box-sizing: border-box;
        }

        .login-container {
            background-color: #ffffff;
            border-radius: 10px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
            padding: 40px;
            width: 100%;
            max-width: 500px; /* 适当加宽以适应多行文本 */
            transition: all 0.3s ease;
        }

        .login-container:hover {
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.12);
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header h2 {
            color: #333;
            margin-bottom: 10px;
        }

        .login-header p {
            color: #666;
            font-size: 14px;
        }

        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-input, .layui-textarea {
            height: 44px;
            border-radius: 5px;
            padding-left: 40px;
            border-color: #e6e6e6;
        }

        .layui-textarea {
            height: 150px; /* 文本域高度 */
            padding-top: 12px; /* 文本域内边距调整 */
            resize: vertical; /* 允许垂直拉伸 */
        }

        .layui-input:focus, .layui-textarea:focus {
            border-color: #1E9FFF !important;
            box-shadow: 0 0 0 2px rgba(30, 159, 255, 0.2);
        }

        .input-icon {
            position: absolute;
            left: 10px;
            top: 12px;
            color: #999;
            font-size: 18px;
        }

        /* 文本域图标位置调整 */
        .textarea-icon {
            top: 15px; /* 文本域内边距不同，图标位置微调 */
        }

        .layui-btn {
            height: 44px;
            border-radius: 5px;
            background-color: #1E9FFF;
            font-size: 16px;
        }

        .layui-btn:hover {
            background-color: #0D8BD9;
        }

        .login-footer {
            margin-top: 20px;
            text-align: center;
            font-size: 14px;
        }

        .login-footer a {
            color: #1E9FFF;
        }

        .login-footer a:hover {
            text-decoration: underline;
        }

        /* 提示信息样式 */
        .info-message {
            color: #1E9FFF;
            text-align: center;
            margin-bottom: 15px;
            font-size: 13px;
        }

        .success-message {
            color: #009688;
            text-align: center;
            margin-bottom: 15px;
        }

        .error-message {
            color: #FF5722;
            text-align: center;
            margin-bottom: 15px;
        }

        /* 响应式调整 */
        @media (max-width: 480px) {
            .login-container {
                padding: 30px 20px;
            }
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-header">
        <h2><i class="fa fa-comments" aria-hidden="true"></i> 联系管理员</h2>
        <p>如有问题，请填写以下信息，我们会尽快回复您</p>
    </div>

    <div class="info-message">
        <i class="fa fa-info-circle"></i> 工作时间：周一至周五 9:00-18:00
    </div>

    <form class="layui-form" action="#" method="post">
        <!-- 姓名输入 -->
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="input-icon">
                    <i class="fa fa-user" aria-hidden="true"></i>
                </div>
                <input type="text" id="name" name="name" required lay-verify="required" placeholder="请输入您的姓名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 邮箱输入 -->
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="input-icon">
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                </div>
                <input type="email" id="email" name="email" required lay-verify="required|email"
                       placeholder="请输入您的邮箱（用于回复）"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 主题输入 -->
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="input-icon">
                    <i class="fa fa-tag" aria-hidden="true"></i>
                </div>
                <input type="text" id="subject" name="subject" required lay-verify="required"
                       placeholder="请输入问题主题"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 内容输入（文本域） -->
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="input-icon textarea-icon">
                    <i class="fa fa-file-text" aria-hidden="true"></i>
                </div>
                <textarea name="content" id="content" required lay-verify="required" placeholder="请详细描述您的问题..."
                          class="layui-textarea"></textarea>
            </div>
        </div>

        <!-- 提交按钮 -->
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" type="button" lay-submit lay-filter="contact">
                <i class="fa fa-paper-plane" aria-hidden="true"></i> 提交信息
            </button>
            <button style="display: none" id="sub"></button>
        </div>
    </form>

    <div class="login-footer">
        <a href="#" onclick="window.history.back()"><i class="fa fa-arrow-left" aria-hidden="true"></i> 返回</a>
    </div>
</div>

<!-- 引入Layui JS -->
<script src="https://cdn.staticfile.org/layui/2.8.17/layui.min.js"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;

        // 表单提交回调
        form.on('submit(contact)', function (data) {
            submit()
            // 可在这里添加额外的前端验证逻辑
            return false; // 允许表单提交
        });


        function submit() {

            let name = $('#name').val()
            let subject = $('#subject').val()
            let email = $('#email').val()
            let content = $('#content').val()

            $.ajax({
                url: '${pageContext.request.contextPath}/relation',
                type: 'post',
                async: true,
                data: {
                    name: name,
                    subject: subject,
                    email: email,
                    content: content
                }, success: function (res) {
                    if (res === 'success') {
                        layer.msg('发送成功', {icon: 1})
                        $('#name').val('')
                        $('#subject').val('')
                        $('#email').val('')
                        $('#content').val('')
                    } else {
                        layer.msg('发送失败', {icon: 5})
                    }
                }, error: function (res) {
                    layer.msg('发送成功', {icon: 1})
                }
            })
        }


    });
</script>
</body>
</html>